package pers.lolicer.redtidelibrary.utils

import android.content.Context
import androidx.datastore.preferences.core.edit
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import pers.lolicer.redtidelibrary.config.Settings
import pers.lolicer.redtidelibrary.dataStore

suspend fun init(context: Context){
    context.dataStore.edit{ preferences ->
        if(preferences[Settings.test] == null){
            preferences[Settings.test] = 0
        }
    }
}

suspend fun getTest(context: Context): Flow<Any>{
    return context.dataStore.data
        .map { preferences ->
            preferences[Settings.test] ?: 0
        }
}

suspend fun setTest(context: Context, value: Int){
    context.dataStore.edit{ preferences ->
        preferences[Settings.test] = value
    }
}